﻿<controls:ChildWindow xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
                      xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
                      xmlns:controls="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls" 
                      xmlns:System_Windows_Controls_Primitives="clr-namespace:System.Windows.Controls.Primitives;assembly=System.Windows.Controls"
                      xmlns:sdk="http://schemas.microsoft.com/winfx/2006/xaml/presentation/sdk" 
                      xmlns:input="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Input.Toolkit"
                      x:Class="iFinance.Modules.Outgoings.Views.OutgoingsMaintainView"
           Width="460" Height="320" Title="支出明细" x:Name="ucOutgoings">
    <Grid x:Name="LayoutRoot" Margin="2">
        <Grid.RowDefinitions>
            <RowDefinition Height="33" />
            <RowDefinition Height="31"/>
            <RowDefinition Height="32"/>
            <RowDefinition/>
            <RowDefinition Height="24"/>
            <RowDefinition Height="23" />
        </Grid.RowDefinitions>
        <Button x:Name="btnOK" Command="{Binding ConfirmCommand}" Content="确定" Click="OKButton_Click" Width="75" Height="23" HorizontalAlignment="Right" Margin="0,0,79,0" Grid.Row="5" />
        <Button x:Name="btnCancel" Content="取消" Click="CancelButton_Click" Width="75" Height="23" HorizontalAlignment="Right" Margin="0" Grid.Row="5" />
        <StackPanel Orientation="Horizontal" VerticalAlignment="Center" DataContext="{Binding OutgoingsItem}">
            <TextBlock HorizontalAlignment="Center" Margin="4,0,0,0" TextWrapping="Wrap" Text="支出时间" VerticalAlignment="Center"/>
            <controls:DatePicker x:Name="dpDate" Margin="4,0,0,0" SelectedDate="{Binding Date,Mode=TwoWay}"/>
            <TextBlock HorizontalAlignment="Center" Margin="4,0,0,0" TextWrapping="Wrap" Text="支出地点" VerticalAlignment="Center"/>
            <TextBox x:Name="tbLocation" Text="{Binding Location,Mode=TwoWay}" TextWrapping="NoWrap" Width="228" Margin="4,0,0,0" VerticalAlignment="Center"/>
        </StackPanel>
        <StackPanel Orientation="Horizontal" Grid.Row="1" VerticalAlignment="Center">
            <TextBlock HorizontalAlignment="Center" Margin="4,0,0,0" TextWrapping="Wrap" Text="支出类型" VerticalAlignment="Center"/>
            <ComboBox x:Name="cbOutgoingsType" Margin="4,0,0,0" Width="75" SelectedItem="{Binding ElementName=ucOutgoings,Path=DataContext.OutgoingsItem.OutgoingsType ,Mode=TwoWay}" ItemsSource="{Binding List}" DataContext="{Binding OutgoingsTypes}" DisplayMemberPath="Name"/>
            <TextBlock HorizontalAlignment="Center" Margin="4,0,0,0" TextWrapping="Wrap" Text="支出说明" VerticalAlignment="Center"/>
            <TextBox x:Name="tbDescription" Text="{Binding OutgoingsItem.Description,Mode=TwoWay}" TextWrapping="NoWrap" VerticalAlignment="Center" Margin="4,0,0,0" Width="256"/>
        </StackPanel>
        <StackPanel x:Name="spAddDetail" Orientation="Horizontal" Grid.Row="2" VerticalAlignment="Center" DataContext="{Binding OutgoingsItem.OutgoingsDetail}">
            <TextBlock HorizontalAlignment="Center" Margin="4,0,0,0" TextWrapping="Wrap" Text="商品名称" VerticalAlignment="Center"/>
            <sdk:AutoCompleteBox x:Name="acProductName" Width="145" Margin="4,0,0,0" VerticalAlignment="Center" ValueMemberBinding="{Binding Name}" ItemsSource="{Binding Consumables.List}" DataContext="{Binding CurrentItem}" SelectedItem="{Binding CurrentConsumable,Mode=TwoWay}" IsTextCompletionEnabled="True" Text="{Binding ConsumableName,Mode=TwoWay}" >
                <sdk:AutoCompleteBox.ItemTemplate>
                    <DataTemplate>
                        <TextBlock Text="{Binding Name}"/>
                    </DataTemplate>
                </sdk:AutoCompleteBox.ItemTemplate>
            </sdk:AutoCompleteBox>
            <TextBlock HorizontalAlignment="Center" Margin="4,0,0,0" TextWrapping="Wrap" Text="单价" VerticalAlignment="Center"/>
            <TextBox x:Name="tbUnitPrice" Text="{Binding CurrentItem.UnitPrice,StringFormat=N2,Mode=TwoWay}"  TextWrapping="Wrap" Width="75" Margin="4,0,0,0" VerticalAlignment="Center"/>
            <TextBlock HorizontalAlignment="Center" Margin="4,0,0,0" TextWrapping="Wrap" Text="数量" VerticalAlignment="Center"/>
            <!--<TextBox x:Name="tbQty" Text="{Binding CurrentItem.Count,StringFormat=N3,Mode=TwoWay}" TextWrapping="Wrap" Width="75" Margin="4,0,0,0" VerticalAlignment="Center"/>-->
            <input:NumericUpDown x:Name="nudQty" Value="{Binding CurrentItem.Count,Mode=TwoWay}" Width="75" Margin="4,0,0,0" VerticalAlignment="Center" DecimalPlaces="3" Increment="1"/>
            <Button x:Name="btnAdd" Command="{Binding AddDetailCommand}" Content="+" HorizontalAlignment="Center" VerticalAlignment="Center" Width="24" Height="24" Margin="4,0,0,0"/>
        </StackPanel>
        <sdk:DataGrid x:Name="dgOutgoingsDetailList" Grid.Row="3" Margin="0,0,0,4" DataContext="{Binding OutgoingsItem.OutgoingsDetail}" ItemsSource="{Binding List}" AutoGenerateColumns="False" GridLinesVisibility="All">            
            <sdk:DataGrid.Columns>
                <sdk:DataGridTemplateColumn Header="商品名称" MinWidth="150">
                    <sdk:DataGridTemplateColumn.CellTemplate>
                        <DataTemplate>
                            <TextBlock Text="{Binding CurrentConsumable.Name}" HorizontalAlignment="Left" VerticalAlignment="Center" Margin="4,0,0,0"/>
                        </DataTemplate>
                    </sdk:DataGridTemplateColumn.CellTemplate>
                    <sdk:DataGridTemplateColumn.CellEditingTemplate>
                        <DataTemplate>
                            <sdk:AutoCompleteBox x:Name="acProductName" Margin="4,0,0,0" VerticalAlignment="Center" ValueMemberBinding="{Binding Name}" ItemsSource="{Binding Consumables.List}" DataContext="{Binding}" SelectedItem="{Binding CurrentConsumable,Mode=TwoWay}">
                                <sdk:AutoCompleteBox.ItemTemplate>
                                    <DataTemplate>
                                        <TextBlock Text="{Binding Name}"/>
                                    </DataTemplate>
                                </sdk:AutoCompleteBox.ItemTemplate>
                            </sdk:AutoCompleteBox>
                        </DataTemplate>                       
                    </sdk:DataGridTemplateColumn.CellEditingTemplate>
                </sdk:DataGridTemplateColumn>
                <sdk:DataGridTextColumn Header="单价" Binding="{Binding UnitPrice,StringFormat=N2}"/>
                <sdk:DataGridTemplateColumn Header="数量" >
                    <sdk:DataGridTemplateColumn.CellTemplate>
                        <DataTemplate>
                            <TextBlock Text="{Binding Count,StringFormat=N3}" HorizontalAlignment="Left" VerticalAlignment="Center" Margin="4,0,0,0"/>
                        </DataTemplate>
                    </sdk:DataGridTemplateColumn.CellTemplate>
                    <sdk:DataGridTemplateColumn.CellEditingTemplate>
                        <DataTemplate>
                            <input:NumericUpDown Value="{Binding Count,Mode=TwoWay}" Margin="4,0,0,0" VerticalAlignment="Center" DecimalPlaces="3" Increment="1"/>
                        </DataTemplate>
                    </sdk:DataGridTemplateColumn.CellEditingTemplate>
                    </sdk:DataGridTemplateColumn>
                    <sdk:DataGridTemplateColumn Header="操作">
                    <sdk:DataGridTemplateColumn.CellTemplate>
                        <DataTemplate>
                            <Button Content="-"/>
                        </DataTemplate>
                    </sdk:DataGridTemplateColumn.CellTemplate>
                </sdk:DataGridTemplateColumn>
            </sdk:DataGrid.Columns>
        </sdk:DataGrid>
        <StackPanel HorizontalAlignment="Right" Orientation="Horizontal" Grid.Row="4" VerticalAlignment="Center" Margin="0,0,4,0">
            <TextBlock TextWrapping="Wrap" Text="支出总计"/>
            <TextBlock TextWrapping="Wrap" Text="{Binding OutgoingsItem.OutgoingsDetail.TotalAmount,StringFormat=N2}" Margin="4,0,0,0"/>
            <TextBlock TextWrapping="Wrap" Text="元" Margin="4,0,0,0"/>
        </StackPanel>
    </Grid>
</controls:ChildWindow>